import com.alibaba.fastjson.JSON
import com.alibaba.fastjson.JSONObject

/**
 * 1.获取卖家昵称集合
 * select distinct fen_user_nick
 * from shigu_goodsup_sub a,shigu_goods_id_generator b
 * where  a.supper_goods_id=b.good_id and b.web_site='ss'
 */

/*
def reader = new BufferedReader(new FileReader(new File("C:\\Users\\wxc\\Desktop\\nick\\nick2.txt")))
def tmp
def nicks = readFile("C:\\Users\\wxc\\Desktop\\nick\\nick2.txt")
while (tmp = reader.readLine()) {
    nicks.add('"' + tmp + '"')
}

println nicks*/
/**
 * 2.获取指定数据源的记录
 * select jdp_response
 * from jdp_tb_trade
 * where seller_nick in (@第一步结果)
 */
def list = readFile("C:\\Users\\wxc\\Desktop\\nick\\response2.txt")
def out = new PrintWriter(new FileOutputStream("C:\\Users\\wxc\\Desktop\\nick\\response2Amount.txt"))
def result = new BigDecimal(0)
for (String jb : list){
    def amount = getValue "trade_fullinfo_get_response.trade.available_confirm_fee", JSON.parseObject(jb)
    if (amount == '0.00') continue
    result += new BigDecimal(amount)
    out.println amount
}
out.close()
println "存在匹配卖家：" + list.size
print '总金额：' + result

def getValue(exp, obj) {
    def index = exp.indexOf(".")
    if (index == -1)
        return obj.getString(exp)
    def path = exp.substring(0, index)
    def sub = obj.getJSONObject(path)
    exp = exp.substring(index + 1)
    getValue(exp, sub)
}

def readFile(path) {
    def reader = new BufferedReader(new FileReader(path))
    def tmp
    def lines = []
    while (tmp = reader.readLine())
        lines.add tmp
    reader.close()
    lines
}